#!/bin/bash
#############
#Date 2022/11/22
#mail it-arch
#############
echo "##########################################"
echo "Auto Install Nagios                     ##"
echo "Press Ctrl + C to cancel                ##"
echo "Any key to continue                     ##"
echo "##########################################"
read -n 1
/etc/init.d/iptables status >/dev/null 2>&1
if [ $? -eq 0 ]
then
iptables -I INPUT -p tcp --dport 80 -j ACCEPT && 
iptables -I INPUT -p tcp --dport 443 -j ACCEPT &&
#iptables -I INPUT -p tcp --dport 3306 -j ACCEPT && 
iptables-save >/dev/null 2>&1
else
	echo -e "\033[32m iptables is stopd\033[0m"
fi
sed -i "s/SELINUX=enforcing/SELINUX=disabled/"  /etc/selinux/config
setenforce 0
ntpdate -s time1.aliyun.com 
#######################################################
rpm -Uvh http://mirror.webtatic.com/yum/el6/latest.rpm 
yum remove php* -y
yum install php55w  php55w-bcmath php55w-cli php55w-common  php55w-devel php55w-fpm    php55w-gd php55w-imap  php55w-ldap php55w-mbstring  php55w-mysql   php55w-odbc   php55w-pdo   php55w-pear  php55w-pecl-igbinary  php55w-xml php55w-xmlrpc php55w-opcache php55w-intl php55w-pecl-memcache -y
echo -e "\033[32m Linux 源更新完毕！ \033[0m"
echo -e "\033[32m PHP 安装... \033[0m"
#######################################################
echo -e "\033[32m MySQL 安装... \033[0m"
yum -y install gcc gcc-c++ autoconf httpd libxml* mysql mysql-server  httpd-manual mod_ssl mod_perl mod_auth_mysql mysql-connector-odbc mysql-devel libdbi-dbd-mysql net-snmp-devel curl-devel 
###################################################
service httpd start 
service mysqld start 
service php-fpm start 
chkconfig httpd on 
chkconfig mysqld on 
chkconfig php-fpm on 
##############################################
echo -e "\033[32m 创建zabbix账户 \033[0m"
groupadd nagcmd
useradd -G nagcmd nagios
echo "nagios" | passwd --stdin nagios
usermod -a -G nagcmd apache
###################################################
echo -e "\033[32m 建立站点数据 \033[0m"
if [ -d /var/www/html ];then
    cd /var/www/html
else
    mkdir -p /var/www/html && cd /var/www/html
fi
wget http://jaist.dl.sourceforge.net/project/nagios/nagios-4.x/nagios-4.2.3/nagios-4.2.3.tar.gz
tar zxf nagios-4.2.3.tar.gz
cd nagios-4.2.3
./configure --sysconfdir=/etc/nagios --with-command-group=nagcmd --enable-event-broker
make all
make install
make install-init
make install-commandmode
make install-config
make install-webconf
htpasswd -c /etc/nagios/htpasswd.users nagiosadmin
chkconfig --add nagios
chkconfig nagios on
/etc/init.d/nagios start
echo -e "\033[32m 启动服务 \033[0m"
/etc/init.d/httpd restart
###############################################
#plugins Install
wget http://nagios-plugins.org/download/nagios-plugins-2.1.4.tar.gz
tar -xvf nagios-plugins-2.1.4.tar.gz
cd nagios-plugins-2.1.4
.configure --with-nagios-user=nagios --with-nagios-group=nagios
make
make install
/etc/init.d/nagios restart
#################################################
echo -e "\033[32m nagios is Install Success,MySQL user:root  Passwd:edusoho \033[0m"
echo -e "\033[32m edusoho is Install Success,user:Admin  Passwd:edusoho \033[0m"
